class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        res = 0 #总利润
        a,b,c = 0, 0, 1 # 买入，卖出前一天，卖出
        while c < len(prices):
            if prices[c] <= prices[b]:
                if a!=b:
                    res += prices[b] - prices[a]
                a = c
            b = c
            c += 1
        else:
            res += prices[b] - prices[a]
        return res